#include "ParticleSystem.h"

ParticleSystem::ParticleSystem(void)
{
}

ParticleSystem::~ParticleSystem(void)
{
	Clear();
}

void ParticleSystem::Clear()
{
	for (int i=0;i<particles.size();i++)
	{
		delete particles[i];
	}

	particles.clear();
}

void ParticleSystem::AddParticle( Particle *p )
{
	particles.push_back(p);
	p->index=particles.size()-1;
}

void ParticleSystem::GetAccleration( double *accleration )
{
	int index=0;

	for (int i=0;i<particles.size();i++)
	{
		for (int j=0;j<DIM;j++)
		{
			accleration[index++]=particles[i]->force[j]/particles[i]->mass;
		}
	}
}

void ParticleSystem::GetVelocity( double *velocity )
{
	int index=0;

	for (int i=0;i<particles.size();i++)
	{
		for (int j=0;j<DIM;j++)
		{
			velocity[index++]=particles[i]->vel[j];
		}
	}
}

void ParticleSystem::GetPosition( double *position )
{
	int index=0;

	for (int i=0;i<particles.size();i++)
	{
		for (int j=0;j<DIM;j++)
		{
			position[index++]=particles[i]->pos[j];
		}
	}
}

int ParticleSystem::GetScale()
{
	return particles.size()*DIM;
}

Particle::Particle( double *pos, double *vel, double *force, double mass/*=1.0*/ )
{
	for (int i=0;i<DIM;i++)
	{
		this->pos[i]=pos[i];
		this->vel[i]=vel[i];
		this->force[i]=force[i];
	}
	this->mass=mass;
}
